package com.xiaoshu.disruptor.handler;

import com.lmax.disruptor.EventHandler;
import com.xiaoshu.disruptor.MessageEvent;
import com.xiaoshu.websocket.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 功能说明： 判断当前用户是否需要推送消息，如果需要推送消息，则通过Websocket协议，推送消息到前端；
 * com.xiaoshu.disruptor.handler
 *
 * <p>
 * Original @Author: deane.jia-贾亮亮,2021/6/15 14:16
 * <p>
 * Copyright (C)2012-2021 小树盛凯科技 All rights reserved.
 */
@Component
@Slf4j
public class SendMessageEventHandler implements EventHandler<MessageEvent> {
    @Override
    public void onEvent(MessageEvent event, long sequence, boolean endOfBatch) throws Exception {
        log.info("====> [Send Message] info:{}", event.getMethodInfoModel().toString());
        // TODO  step-1 判断是否需要发送消息到登录用户；如果判断达到升级标准，则进行升级操作；
        if(true){
            String message = "level is grade";
            Object[] params = event.getMethodInfoModel().getParams();
            String toUserId = (String)params[0];
            WebSocketServer.sendInfo(message,toUserId);
        }
    }
}
